package com.example.demo11.mapper;

import com.example.demo11.entity.UserBean;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {
    //查询，可以实现登录功能
    @Select("SELECT * FROM user WHERE username = #{username} AND password = #{password}")
    UserBean getInfo(@Param("username") String username, @Param("password") String password);

    //多个参数要加@Param修饰
    //增加，可以实现注册功能
    @Insert("insert into user(username, password) values(#{username}, #{password})")
    void saveInfo(@Param("username") String username, @Param("password") String password);

    // UserMapper.java 新增方法
    @Select("SELECT * FROM user")
    List<UserBean> getAllUsers();

    @Select("SELECT * FROM user WHERE username LIKE CONCAT('%', #{keyword}, '%')")
    List<UserBean> searchUsers(@Param("keyword") String keyword);

    @Delete("DELETE FROM user WHERE id = #{id}")
    void deleteById(Integer id);

    @Select("SELECT * FROM user WHERE id = #{id}")
    UserBean getById(Integer id);

    // UserMapper.java
    @Update("UPDATE user SET username=#{username}, password=#{password} WHERE id=#{id}")
    void updateUser(UserBean user);
}